package com.tfswx.jcyw.dmzc.api;

import cn.hutool.core.codec.Base64;
import com.intellij.openapi.project.Project;
import com.tfswx.jcyw.dmzc.api.anno.Request;
import com.tfswx.jcyw.dmzc.api.dto.GcxxGetInputDTO;
import com.tfswx.jcyw.dmzc.api.dto.GcxxGetOutputDTO;
import com.tfswx.jcyw.dmzc.config.CommonData;
import com.tfswx.jcyw.dmzc.linstener.MyProjectListener;
import com.tfswx.jcyw.dmzc.service.XmxxService;
import com.tfswx.jcyw.dmzc.util.ProjectUtil;

/**
 * @author ricky
 * @date 2023/3/13
 */
@Request("khd")
public class KhdController {

    @Request("getGcxx")
    public GcxxGetOutputDTO getGcxx(GcxxGetInputDTO inputDTO) {
        Project project = MyProjectListener.getProject(inputDTO.getGcmc());
        if (project == null) {
            return null;
        }
        XmxxService xmxxService = XmxxService.getInstance(project);

        String openFilePath = ProjectUtil.getOpenFilePath(project);

        GcxxGetOutputDTO gcxxGetOutputDTO = new GcxxGetOutputDTO();
        if (CommonData.imageByte != null) {
            String base64 = Base64.encode(CommonData.imageByte);
            gcxxGetOutputDTO.setTpBase64(base64);
        }


        gcxxGetOutputDTO.setGcmc(project.getName());
        gcxxGetOutputDTO.setXmlx(xmxxService.getXmlx());
        gcxxGetOutputDTO.setZcywjbh(openFilePath);

        return gcxxGetOutputDTO;
    }
}
